/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div class="item-title">
      <router-link
        class="back"
        :to="{name:'news_list', params:{currentPage:$route.params.currentPage}}"
        title="返回列表"
      >
        <i class="fa fa-arrow-circle-o-left"></i>
      </router-link>
      <div class="subject">
        <h3>新闻管理</h3>
        <h5>网站系统新闻评论索引与管理</h5>
      </div>
    </div>
    <div
      id="explanation"
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>新闻评论管理, 由总平台设置管理.</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>
    <div class="mDiv">
      <div class="ftitle">
        <h3>评论列表</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
    </div>

    <div class="tablebox">
      <el-table :data="tableData" ref="multipleTable" style="width: 100%;">
        <el-table-column label="评论内容" prop="content" width="400" show-overflow-tooltip></el-table-column>
        <el-table-column label="评论者" prop="commenter" width="150"></el-table-column>
        <el-table-column label="评论时间" prop="add_time_desc" width="200"></el-table-column>
        <el-table-column label="审核状态" width="120">
          <template slot-scope="scope">
            <span v-if="scope.row.check_type == 0">未审核</span>
            <span v-else-if="scope.row.check_type == 1" style="color:green">通过</span>
            <span v-else style="color:red">拒绝</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <div v-if="scope.row.check_type == 0">
              <el-button-group>
                <el-button
                  @click="checkComment(scope.row.comment_id, 1)"
                  icon="el-icon-check"
                  size="small"
                >通过</el-button>
                <el-button
                  @click="checkComment(scope.row.comment_id, 2)"
                  icon="el-icon-close"
                  size="small"
                >拒绝</el-button>
              </el-button-group>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 10
    };
  },
  created() {
    this.getPage();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      this.request
        .get("/mall/news_comment/page", {
          params: {
            article_id: this.$route.params.id,
            page: that.currentPage,
            size: that.pageSize
          }
        })
        .then(function(res) {
          that.tableData = res.records;
          that.totalCount = res.total;
        });
    },
    refresh() {
      this.getPage();
      this.$message.success("刷新成功！");
    },
    checkComment(id, type) {
      var that = this;
      this.request
        .put("mall/news_comment/check?comment_id=" + id + "&check_type=" + type)
        .then(function(res) {
          if (res.status == 1) {
            that.$message.success("操作成功");
            that.getPage();
          }
        });
    }
  }
};
</script>

<style scoped>
</style>
